package com.csx.queue;

import java.util.Random;

/**
 * 测试类
 * @author 陈胤训
 * <p>
 * create: 2019-04-02 15:17
 **/
public class Mian {

    /**  测试使用q 运行opCount个 enqueue 和 dequeue 操作所需要的时间 单位秒 */
    private static double testQueue(Queue<Integer> q,int opCount) throws IllegalAccessException {

        /** 返回的是纳秒  纳秒与秒 相差 10的9次方  */
        long startTime = System.nanoTime();

        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            q.enqueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            q.dequeue();
        }

        long endTime = System.nanoTime();

        return (endTime - startTime) / 1000000000.0;
    }

    public static void main(String[] args) throws IllegalAccessException {
        int opCount = 100000;
        ArrayQueue arrayQueue = new ArrayQueue();
        double v = testQueue(arrayQueue, opCount);
        System.out.println("ArrayQueue: "+v);
        LoopQueue loopQueue = new LoopQueue();
        double v1 = testQueue(loopQueue, opCount);
        System.out.println("LoopQueue: "+v1);
    }
}
